<template>
  <div class="scalePage">
    <div class="test">
      <div class="left">
        <el-tree
          :data="treeList"
          :props="props"
          node-key="id"
          :current-node-key="'1024980990084376673'"
          :default-expanded-keys="['1024980958136362977']"
          :default-checked-keys="['1024980958136362977']"
          highlight-current
          @node-click="handleNodeClick"
          :expand-on-click-node="false"
        ></el-tree>
      </div>

      <div class="right">
        <!-- 机构 -->
        <el-card class="card1">
          <template #header>
            <div>
              <span>作业范围</span>
              <div style="float: right; margin-right: 40px">
                <el-button>编辑</el-button>
              </div>
            </div>
          </template>
          <!-- 地图 -->
          <div class="search">
            <div class="keywords">
              <label>地区关键词：<el-input v-model="keyword" placeholder="请输入地区关键词"></el-input></label>
            </div>
          </div>
          <div style="padding: 22px 0px">
            <div class="map">
              <template>
                <baidu-map class="map" center="杭州">
                <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
                <bm-local-search :keyword="keyword" :auto-viewport="true" :location="location"></bm-local-search>
                <bm-polygon :path="polygonPath" stroke-color="blue" :stroke-opacity="0.5" :stroke-weight="2" :editing="true" @lineupdate="updatePolygonPath"/>
              </baidu-map>
              </template>
            </div>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
import { getOrgizationTree } from '@/api/organ'
export default {
  name: 'Institutions-Index',
  data () {
    return {
      treeList: [], // 机构tree
      props: {
        label: 'name',
        children: 'children',
        id: 'id'
      },
      center: { lng: 0, lat: 0 },
      zoom: 3,
      keyword: '',
      polygonPath: [
        { lng: 120.19, lat: 30.26 },
        { lng: 120.29455, lat: 30.10932 },
        { lng: 120.203461, lat: 30.21336 }
      ]
    }
  },
  created () {
    this.getTreeList()
  },
  methods: {
    async handleNodeClick (data) {
      console.log(data)
    },
    async getTreeList () {
      const res = await getOrgizationTree()
      // console.log(res.data);
      this.treeList = JSON.parse(res.data)
      // console.log(this.treeList);
    },
    handler ({ BMap, map }) {
      console.log(BMap, map)
      this.center.lng = 116.404
      this.center.lat = 39.915
      this.zoom = 15
    },
    updatePolygonPath (e) {
      this.polygonPath = e.target.getPath()
    },
    addPolygonPoint () {
      this.polygonPath.push({ lng: 116.404, lat: 39.915 })
    }
  }
}
</script>

<style lang="scss" scoped>
.scalePage {
  width: 100%;
  padding: 20px;
  min-height: 870px;
  padding-top: 23px !important;
  .test {
    width: 100%;
    display: -webkit-box;
    .left {
      background-color: #fff;
      border-radius: 4px;
      height: auto !important;
      width: 214px;
      padding-left: 9px;
      padding-top: 10px;
      ::v-deep .el-tree {
        padding-left: 10px;
        margin-top: 5px !important;
        // 不旋转
        .el-tree-node__expand-icon.expanded {
          -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
        }
        .el-tree-node {
          margin: 5px 0 !important;
        }
        .el-tree-node__content {
          margin-right: 20px;
          height: 30px !important;
        }
      }
      // 高亮
      ::v-deep
        .el-tree--highlight-current
        .el-tree-node.is-current
        > .el-tree-node__content {
        background-color: #fff;
        color: #ff7a63 !important;
      }
      // 一级未展开
      ::v-deep .el-icon-caret-right:before {
        background: url()
          no-repeat;
        width: 14px;
        height: 13px;
        background-size: 100% 100%;
        content: "";
        display: block;
      }
      // 一级展开
      ::v-deep .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
        transform: none !important;
        background: url()
          no-repeat;
        width: 14px;
        height: 13px;
        background-size: 100% 100%;
        content: "";
        display: block;
      }
      // 二级未展开
      ::v-deep .el-tree-node__children .el-icon-caret-right:before {
        background: url()
          no-repeat;
        width: 14px;
        height: 14px;
        background-size: 100% 100%;
        content: "";
        display: block;
      }
      // 二级展开
      ::v-deep
        .el-tree-node__children
        .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
        transform: none !important;
        background: url()
          no-repeat;
        width: 14px;
        height: 14px;
        background-size: 100% 100%;
        content: "";
        display: block;
      }
      // 没有子节点
      ::v-deep .el-tree-node__expand-icon.is-leaf::before {
        background: none;
        content: "";
        display: block;
        width: 14px;
        height: 14px;
        font-size: 14px;
        background-size: 14px;
      }
    }
    .right {
      background-color: #f3f4f7;
      border-radius: 4px;
      -webkit-box-flex: 1;
      margin-left: 20px;
    }
  }
}
::v-deep .el-card__header {
  padding: 0 0 0 25px;
  border-bottom: 0;
  background: #f8faff;
  font-size: 18px;
  font-weight: 700;
  color: #2a2929;
  height: 60px;
  line-height: 60px;
  .el-button {
    padding: 10px 20px;
    background-color: #e15536;
    color: #fff;
    width: 90px;
    border-radius: 5px;
    font-weight: 400;
    border: 1px solid #e15536;
  }
}
::v-deep .el-card__body {
  padding: 25px 25px;
}
.map {
  width: 100%;
  height: 668px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-box-pack: center;
}
::v-deep .search {
  display: flex;
  .keywords {
    margin-right: 30px;
    label {
      color: #20232a;
      font-size: 14px;
    }
    .el-input {
      width: 230px;
    }
  }
  .map {
  width: 100%;
  height: 400px;
}
}
</style>
